package UserDao.UserDaoImpl;

import DBUtil.DBUtil;
import UserDao.UserDao;
import entity.User;

import java.util.List;
import java.util.Map;

public class UserDaoImpl implements UserDao {

    public User loginUser(String userId, String userPass) {
        User user=null;
        List<Map<String, Object>> list = DBUtil.executeQuery("select * from user where userid=? and userpass=?", userId, userPass);
        for (Map<String, Object> u : list) {
            user=new User();
            user.setUserId(u.get("userid").toString());
            user.setUserPass(u.get("userpass").toString());
            user.setUserStatus(Integer.parseInt(u.get("userstatus").toString()));

        }
        return user;
    }

    public int addUser(User user) {
        int r=0;
        r=DBUtil.executeUpdate("INSERT INTO `user` VALUES (?,?,?)",user.getUserId(),user.getUserPass(),user.getUserStatus());
        return r;
    }
}
